package com.stgl.action;

import com.stgl.service.CampusService;
import com.stgl.util.MD5;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@Controller
@EnableAutoConfiguration
@RequestMapping("/campus")
public class campus {
    @Resource
    private CampusService campusService;

    @RequestMapping("getCampusBycsid.html")
    @ResponseBody
    public Map<String,Object>getCampusBycsid(HttpServletRequest request, HttpServletResponse response){
        HttpSession session=((HttpServletRequest)request).getSession();
        if(session.getAttribute("csid")!=null){
            String csid=session.getAttribute("csid").toString();
            Map<String,Object>rmap=campusService.getCampusBycsid(csid);
            return rmap;
        }else {
            return new HashMap<>();
        }
    }


    @RequestMapping("updateCampus.html")
    @ResponseBody
    public Boolean updateCampus(HttpServletRequest request, HttpServletResponse response){
        String csid=request.getParameter("csid").trim();
        String csname=request.getParameter("csname").trim();
        String jianjie=request.getParameter("jianjie").trim();
        Map<String,Object>gmap=new HashMap<String,Object>();
        gmap.put("csid",csid);
        gmap.put("csname",csname);
        gmap.put("jianjie",jianjie);
        int i=campusService.updateCampus(gmap);
        if(i>=0){
            return true;
        }
        return false;
    }

}
